<%@ page import="org.cscarioni.Sprint" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />
        <title>Sprint Panel</title>
        <g:javascript library="jquery"/>
        <g:javascript  src="jquery/jquery.jcontext.1.0.js"/>
        <g:javascript  src="jquery/jquery.jqmodal.js"/>
        <g:javascript  src="jquery/jquery.form.js"/>
        <g:javascript  src="jquery/jquery-ui-1.7.2.custom.min.js"/>
        <link rel="stylesheet" href="${resource(dir:'css',file:'contextmenu.css')}" />  
        <link rel="stylesheet" href="${resource(dir:'css',file:'jqmodal.css')}" /> 
        <link rel="stylesheet" href="${resource(dir:'css/ui-lightness',file:'jquery-ui-1.7.2.custom.css')}" /> 
     <script>
     	$(function(){
     		$("#cardHolder").jqm({modal:true,zIndex: 500});
         });
     	 
     	 function showCardModal(){		
     		$("#cardHolder").jqmShow();
     		$("#cardHolder").show();
          }
     	function callbackCardCreated(){
        	$("#cardHolder").jqmHide();
        	window.location="<g:createLink controller='sprint' action='tableView' params='[sprintId:sprint.id,userId:user?.id]'/>";
        }
     </script>
     </head>
     <body>
        <div>
    		<g:link class="create" action="showPanelForSprint" controller="sprint" params="[sprintId:sprint.id]">Show Panel View</g:link>
    	</div>
     	<div style="width: 100%">
    		${sprint}
    	</div>
    	<div>
    		<g:remoteLink  onComplete="showCardModal();" controller="card" action="create" params="[sprintId:sprint.id]" update="cardHolder" >Add Task</g:remoteLink>
    	</div>
    	<div class="formDiv">
    		<g:form name="filterForm" action="tableView">
    		 <g:select name="userId" from="${org.cscarioni.User.list()}" optionKey="id" noSelection="${['-1':'-- no selection --']}" value="${user?.id}"/>
    		 <g:hiddenField name="sprintId" value="${sprint.id}"/>
    		 <g:submitButton value="Filter" name="filter"/>
    		 </g:form>
    	</div>
     	<table id="tableCArds">
     		<tr>
     			<td>
     				Story
     		    </td>
     		    <td>
     				Titulo
     		    </td>
     		    <td>
     				Descripcion
     		    </td>
     		    <td>
     				Usuario
     		    </td>
     		    <td>
     				Estado
     		    </td>
     		    <td>
     				Tiempo Estimado
     		    </td>
     		    <td>
     				Tiempo Restante
     		    </td>
     		    <td></td>
     		</tr>
     		<div>
     		    <%
					def totalRestantes=0;
					def totalEstimadas=0;
				%>
     		<g:each in="${sprint.panel.columns}"> 			
     			<g:collect in="${it.cards}" var="card" expr="if(it.user==user || !user) return it">
     			  <g:if test="${card}">
     			  <g:formRemote id="theform${card?.id}" name="form" url="[controller:'card',action:'save']">	
     			  <tr>	
     				<td>
     					<g:select name="story.id" from="${card?.sprint.project.backlog.stories}" optionKey="id" optionValue="name" value="${card?.story?.id}"/>
     				</td>
     				<td>
     					<g:textField name="title" value="${card?.title}"/>
     				</td>
     				<td>
     					<g:textField name="description" value="${card?.description}"/>
     				</td>
     				<td>
     					<g:select name="user.id" from="${org.cscarioni.User.list()}" optionKey="id" optionValue="username" value="${card?.user?.id}"/>
     				</td>
     				<td>
     					<g:select name="column.id" from="${card.sprint.panel.columns}" optionKey="id" optionValue="name" value="${card?.column?.id}"/>
     				</td>
     				<td>
     					<g:textField name="estimatedTime" value="${card?.estimatedTime}"/>
     					<%totalEstimadas=totalEstimadas+card?.estimatedTime%>
     				</td>
     				<td>
     					<g:textField name="remainingTime" value="${card?.remainingTime}"/>
     					<%totalRestantes=totalRestantes+card?.remainingTime%>
     				</td>
     				<td>
     				<div id="submitForm" class="submitForm" style="float: right;cursor: pointer;">
						<input type="submit" value="Save"/>
					</div>
     				</td>
     			   </tr>	
     			    <g:hiddenField name="id" value="${card?.id}"/>
					 <g:hiddenField name="sprint.id" value="${sprint.id}"/>
     			   </g:formRemote>
     			   </g:if>
     			</g:collect>
     		</g:each>
     		</div>
     		<div>	     			
     			<div>Estimadas: ${totalEstimadas}</div>
     			<div>Restantes: ${totalRestantes}</div>   		
     		</div>
     		<div id="cardHolder" class="jqmWindow">
    	    </div> 
     	</table>
     </body>
 </html>          